package com.monster.servlet.player;

import com.alibaba.fastjson.JSON;
import com.monster.pojo.Song;
import com.monster.service.SongService;
import com.monster.service.SongServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/music/play_song")
public class PlaySongServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Long mid = Long.parseLong(request.getParameter("mid"));
        SongService ss = new SongServiceImpl();
        Song song = ss.getSongById(mid);
        String songJSON = JSON.toJSONString(song, true);
        PrintWriter out = response.getWriter();
        out.print(songJSON);
        out.flush();
        out.close();

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
